 $(document).ready(function () {
            var icon = "<i class='fa fa-times-circle'></i>";
            var form = $('form.js-ajax-forms');
            var formloading = false;
            form.validate({
                //验证规则
                rules: {
                    Title: {
                        required: true
                    },
                    ProjectName: {    
                        required: true
                    },
                    InOutType:{
                        required: true
                    },
                    ContractType: {
                        required: true
                    },
                    FPIDName: {
                        required: true
                    },
                    SPIDName: {
                        required: true
                    },
                    Bill: {
                        required: true
                    },
                    YearBill: {
                        required: true
                    },
                    MonthBill: {
                        required: true
                    },
                    Bond: {
                        required: true
                    },
                    UserName: {
                        required: true
                    },
                    LeaderName: {
                        required: true
                    },
                    DepName: {
                        required: true
                    },
                    CreateDate:{
                        required: true
                    }
                },
                //验证未通过提示消息
                messages: {
                    Title:{
                        required: icon + "请输入合同名称"
                    },
                    ProjectName:{
                        required: icon + "选择入项目名称"
                    },
                    InOutType :{
                        required: icon + "请选择合同收支类型"
                    },
                    ContractType:{
                        required: icon + "请输入合同类型"
                    },
                    FPIDName:{
                        required: icon + "请输入甲方名称"
                    },
                    SPIDName:{
                        required: icon + "请输入乙方名称"
                    },
                    Bill:{
                        required: icon + "请输入合同金额"
                    },
                    YearBill: {
                        required: icon + "请输入合同年金额"
                    },
                    MonthBill: {
                        required: icon + "请输入合同月金额"
                    },
                    Bond: {
                        required: icon + "请输入合同保证金"
                    },
                    UserName: {
                        required: icon + "请输入合同签订人"
                    },
                    LeaderName: {
                        required: icon + "请输入签约领导"
                    },
                    DepName:{
                        required:icon + "请选择承办部门"
                    },
                    CreateDate:{
                        required:icon + "请选择合同创建时间"
                    }
                },
                //验证通过，提交表单
                submitHandler : function(forms) {
                    if (formloading)
                    return;
                    $(forms).ajaxSubmit({
                        url : form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
                        dataType : 'json',
                        beforeSubmit : function(arr, $form, options) {
                            formloading = true;
                        },
                        success : function(data, statusText, xhr, $form) {
                            formloading = false;
                            if (data.status) {
                                //添加成功
                                swal({
                                    title: "继续操作？",
                                    text: "操作成功！",
                                    type: "success",
                                    showCancelButton: true,
                                    confirmButtonColor: "#DD6B55",
                                    confirmButtonText: "确认",
                                    cancelButtonText: "返回",
                                    closeOnConfirm: false,
                                    closeOnCancel: false
                                },
                                function (isConfirm) {
                                    if (isConfirm) {
                                        //document.location.reload();
                                        document.location.href = "/index.php?m=Admin&c=Contract&a=ContractBody&ContractID="+data.info.ID+"&ContractType="+data.info.ContractType;
                                    } else {
                                       // document.location.href = "{:U('Admin/Contract/ContractBody')}";
                                        return true;
                                    }
                                }); 
                            } else {
                                swal("操作失败", data.info, "error");
                            }
                        }
                    });
                }
            });
        });


        var FPWriteDate = {
            elem: '#FPWriteDate',
            format: 'YYYY-MM-DD',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
               
            }
        };
        laydate(FPWriteDate);

        var SPWriteDate = {
            elem: '#SPWriteDate',
            format: 'YYYY-MM-DD',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
               
            }
        };
        laydate(SPWriteDate);

         var CreateDate = {
            elem: '#CreateDate',
            format: 'YYYY-MM-DD',
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istime: true,
            istoday: false,
            choose: function (datas) {
               
            }
        };
        laydate(CreateDate);
    
    $('#ContractPartner').on('click', function(){
        layer.open({
            title:'录入与合同相关的单位',
            type: 2,
            area: ['800px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: "/index.php?m=Admin&c=Contract&a=ContractPartner"
        });
    });



    function cpdelete(e){
        $(e).parent().remove();
        var m=$('#multipart').val();
        $('#multipart').val(parseInt(m)-1);
        changepxx();
    }

    var FPID,SPID
    $(document).ready(function(){
        var judge=$('#InOutType').val()
        changejy(judge);
        $('#InOutType').change(function(){
         judge=$(this).val();
          changejy(judge);
          $('#SPID').val('');
          $('#FPID').val('');
          $('#FPIDName').val('');
          $('#SPIDName').val('');
        })

        
        function changejy(e){
            //收入合同
            if(e==1){
            FPID='/index.php?m=Admin&c=Contract&a=Organizationselect&type=FPID';
            SPID='/index.php?m=Admin&c=Contract&a=Customerselect&type=SPID'
            }else{
            //支出合同
            FPID='/index.php?m=Admin&c=Contract&a=Customerselect&type=FPID'
            SPID='/index.php?m=Admin&c=Contract&a=Organizationselect&type=SPID';
            }
        }

    });

    // 打开甲方

   $('#FPIDName').on('click', function(){
        layer.open({
                title:'选择甲方',
                type: 2,
                area: ['850px', '600px'],
                fixed: false, //不固定
                maxmin: true,
                content: FPID
            });
    });
 
  
    // 打开乙方
   $('#SPIDName').on('click', function(){
        layer.open({
                title:'选择乙方',
                type: 2,
                area: ['850px', '600px'],
                fixed: false, //不固定
                maxmin: true,
                content: SPID
            });
    });
 
    $('#ProjectName').on('click', function(){
        layer.open({
            title:'录入与合同相关的项目',
            type: 2,
            area: ['800px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: "/index.php?m=Admin&c=ProjectInOut&a=select"
        });
    });
  
